﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;

namespace QWeiBoN.Util
{
    /// <summary>
    /// 话题工具类
    /// </summary>
    public class TopicsUtil
    {
        /// <summary>
        /// 得到最近输入的话题列表
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public static List<string> GetRecentList(int count = 0)
        {
            var topicsList = (List<string>)IsoSetting.Get(IsoHelper.TopicsKey);
            if (null == topicsList)
            {
                return new List<string>();
            }
            if (count > 0)
            {
                count = Math.Min(count, topicsList.Count);
                topicsList = topicsList.Take(count).ToList();
            }
            return topicsList;
        }

        /// <summary>
        /// 设置新的话题
        /// </summary>
        /// <param name="topicsStr"></param>
        public static void SetTopics(string topicsStr)
        {
            var topicsList = new List<string> { topicsStr };
            var allTopicsList = GetRecentList();
            if (null != allTopicsList && allTopicsList.Count > 0)
            {
                foreach (string item in allTopicsList)
                {
                    if (string.Compare(item, topicsStr, StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        return;
                    }
                }
            }
            var rs = allTopicsList == null ? topicsList : (topicsList.Concat(allTopicsList).Take(10).ToList());
            IsoSetting.Set(IsoHelper.TopicsKey, rs);
        }
    }
}
